home *** CD-ROM | disk | FTP | other *** search
- ' this structure is used to demonstrate the Array.Sort method
-
- Structure Employee
- Public FirstName As String
- Public LastName As String
- Public HireDate As Date
-
- Sub New(ByVal FirstName As String, ByVal LastName As String, _
- ByVal HireDate As Date)
- Me.FirstName = FirstName
- Me.LastName = LastName
- Me.HireDate = HireDate
- End Sub
-
- ' A function to display an element easily
- Function Description() As String
- Return FirstName & " " & LastName & _
- " (hired on " & HireDate.ToShortDateString & ")"
- End Function
- End Structure
-
- ' this class is used to sort a SortedList in reverse order
-
- Class ReverseStringComparer
- Implements IComparer
-
- Function CompareValues(ByVal x As Object, ByVal y As Object) As Integer _
- Implements IComparer.Compare
- ' Just change the sign of the result of the StrComp.
- Return -StrComp(x.ToString, y.ToString)
- End Function
- End Class
-
- ' a collection class with fixed membership
-
- Class PowersOfTwoCollection
- Inherits System.Collections.ReadOnlyCollectionBase
-
- Sub New(ByVal MaxExponent As Integer)
- MyBase.New()
-
- ' Fill the inner ArrayList object.
- Dim index As Integer
- For Index = 0 To MaxExponent
- InnerList.Add(2 ^ Index)
- Next
- End Sub
-
- ' Support for the Item element (read-only).
- Default ReadOnly Property Item(ByVal Exponent As Integer) As Long
- Get
- Return CLng(InnerList.Item(Exponent))
- End Get
- End Property
- End Class
-
- 'a class used to demonstrate the SquareCollection class
-
- Class Square
- Public Side As Single
-
- ' A simple constructor
- Sub New(ByVal side As Single)
- Me.Side = side
- End Sub
- End Class
-
- ' A collection object that can only store Square objects.
-
- Class SquareCollection
- Inherits System.Collections.CollectionBase
-
- ' You can add only Square objects to this collection.
- Sub Add(ByVal value As Square)
- InnerList.Add(value)
- ' keep the total area updated
- m_TotalArea += (value.Side * value.Side)
- End Sub
-
- ' The Item property sets or returns a Square object.
- Default Property Item(ByVal index As Integer) As Square
- Get
- Return CType(InnerList.Item(index), Square)
- End Get
- Set(ByVal Value As Square)
- InnerList.Item(index) = Value
- End Set
- End Property
-
- ' keep track of the total area of squares
- Dim m_TotalArea As Single
-
- ReadOnly Property TotalArea() As Single
- Get
- Return m_TotalArea
- End Get
- End Property
-
- Function Create(ByVal Side As Single) As Square
- Create = New Square(Side)
- Add(Create)
- End Function
-
- Protected Overrides Sub OnRemoveComplete(ByVal index As Integer, ByVal value As Object)
- ' get a reference to the square being removed
- Dim sq As Square = CType(value, Square)
- ' keep the total area updated.
- m_TotalArea -= (sq.Side * sq.Side)
- End Sub
- End Class
-
- ' a class that inherits from DictionaryBase
-
- Class SquareDictionary
- Inherits System.Collections.DictionaryBase
-
- Sub Add(ByVal Key As String, ByVal Value As Square)
- Dictionary.Add(Key, Value)
- End Sub
-
- Function Create(ByVal Key As String, ByVal Side As Single) As Square
- Create = New Square(Side)
- ' Note that we use the function name as a local variable.
- Dictionary.Add(Key, Create)
- End Function
-
- Default Property Item(ByVal Key As String) As Square
- Get
- Return CType(Dictionary.Item(Key), Square)
- End Get
- Set(ByVal Value As Square)
- Dictionary.Item(Key) = Value
- End Set
- End Property
- End Class
-
-